package nu.aing.P20140421;

/**
 * @author memekmaut@gmail.com
 */
public class TaroString {
    
    public static void main(String[] args) {
        TaroString obj = new TaroString();
        System.out.println(obj.getAnswer("XCYAZTX") );
        System.out.println(obj.getAnswer("CTA") );
        System.out.println(obj.getAnswer("ACBBAT") );
        System.out.println(obj.getAnswer("SGHDJHFIOPUFUHCHIOJBHAUINUIT") );
        System.out.println(obj.getAnswer("CCCATT") );
    }
    
    public String getAnswer(String S) {
        int i = 0;
        while(S.length() > 3) {
            if(S.charAt(0) != 'C') S = S.replaceAll("["+S.charAt(0)+"]", "");
            if(S.length() > 2 && S.charAt(1) != 'A') S = S.replaceAll("["+S.charAt(1)+"]", "");
            if(S.length() > 3 && S.charAt(2) != 'T') S = S.replaceAll("["+S.charAt(2)+"]", "");
            i = i > S.length() - 1 ? 0 : ++i;
        }
        return S.equals("CAT") ? "Possible" : "Impossible";
    }
    
}
